<template>
	<view class="refund">
				<view class="item_content">
					<image :src="goods.image||'/pagesB/static/微信图片_20201124091755.png'" mode=""></image>
					<view class="ItemContent">
						<view class="title">{{goods.name}}</view>
						<view class="parameter">
							<view class="parameter1">{{ goods.option_name }}</view>
						</view>
						<view class="price_ctrlbox">
							<view class="price">￥{{ goods.price }}</view>
							<view class="ctrlbox">x{{ goods.quantity }}</view>
						</view>
					</view>
				</view>
				<view class="order_title">
					<view class="title_left">退款原因</view>
					<input type="text" v-model="reason" placeholder="请输入退款原因" />
				</view>
				<view class="order_title">
					<view class="title_left">退款金额</view>
					<input type="text" v-model="money" @input="mm" placeholder="不可超过商品价格" />
					<view class="price">元</view>
				</view>
				<view class="voucher">
					<view class="voucher_title">
						上传凭证
					</view>
					<view class="voucher_content">
						<image v-if="img != ''" v-for="i in img" :key="i" :src="'http://qiniu.feelmao.com/'+i" class="sctu"></image>
						<view class="jia" @click="shangchuan">
							+
						</view>
					</view>
				</view>
				<view class="button">
					<button type="warn" @click="addmanagement">保存</button>
				</view>
	</view>
</template>

<script>
	import htzImageUpload from '@/components/htz-image-upload/htz-image-upload.vue'
	import {requestUrl,imageUrl} from '@/common/config.js'
	import md5 from '@/common/api/md5.js'
	// import from "@/common/utils/qiniu.min.js"
	export default {
		        components: {
		            htzImageUpload,
		        },
		data() {
			return {
				reason:'',
				money:'',
				img:[],
				Url:'',
				goods:[],
				id:''
			};
		},
		onShow() {
			this.goods = JSON.parse(uni.getStorageSync('goods'));
			console.log(this.goods)
			let time = Math.round(new Date().getTime() / 1000).toString()
			let _this = this
			let Time = ['time', time].join('=')
			let Access_token = ['access_token', this.access_token].join('=')
			let content = ['content=pinet.FeiMao.2017'].join()
			let arr = [content, Time].sort(function(a, b) {
				a - b
			})
			let newarr = md5(arr.join('&'))
			uni.request({
				url: requestUrl+'/app/upload/getUploadConfig',
				method: "GET",
				data: {
					time: time,
					sign: newarr,
				},
				success: function(res) {
					console.log(res)
					_this.Url=res.data.content
				}
			});
		},
		onLoad(e) {
			id=e.id
		},
		methods:{
			mm(){
				if(this.money>this.goods.price){
					this.money=this.goods.price
				}
			},
			shangchuan(){
				let _this=this
				uni.chooseImage({
					count: 9, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择
					success: (res1) => {
						console.log(res1)
						this.$UploadImg(res1.tempFilePaths[0],_this.Url.token).then(res=>{
							console.log(res)
							this.img.push(res.key)
						})
					}
				});
			},
			addmanagement(){
				if(this.reason==''){
					return uni.showToast({
						title:'原因不能为空'
					})
				}
				if(this.money==''){
					return uni.showToast({
						title:'金额不能为空'
					})
				}
				if(this.money>this.goods.price){
					return uni.showToast({
						title:'金额不能大于'+this.goods.price
					})
				}
				this.goods.reason=this.reason
				this.goods.money=this.money
				this.goods.img=this.img
				uni.setStorage({
					key: 'goods',
					data: JSON.stringify(this.goods),
					success: function () {
					}
				});
				if(id==1){
					uni.navigateTo({
						url:'/pagesB/orderdetails/refound1?id=1'
					})
				}else{
					uni.navigateTo({
						url:'/pagesB/orderdetails/refound1'
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.refund{
		background-color: #f3f4f5;
		height: 100%;
		padding-top: 20rpx;
			.item_content {
				display: flex;
				padding: 20rpx;
				border-bottom: 1px solid #eeeeee;
				background-color: #fff;
				margin-bottom: 10rpx;
				image {
					height: 180rpx;
					width: 180rpx;
					margin-right: 16rpx;
				}
				.ItemContent {
					flex: 1;
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					.title {
						height: 72rpx;
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #111111;
					}
					.parameter {
						height: 34rpx;
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #9da5a8;
					}
					.price_ctrlbox {
						display: flex;
						justify-content: space-between;
					}
					.price {
						font-size: 28rpx;
						font-family: PingFangSC-Medium, PingFang SC;
						font-weight: 500;
						color: #111111;
					}
					.ctrlbox {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #9da5a8;
					}
				}
			}
			.order_price1 {
				padding: 0 24rpx 24rpx 24rpx;
			}
			.order_price {
				margin-top: 24rpx;
				height: 100%;
				display: flex;
				justify-content: space-between;
				.price_left {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #111111;
				}
				.price_right {
					font-size: 24rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #111111;
				}
				.price_right1 {
					font-size: 28rpx;
					font-family: PingFangSC-Medium, PingFang SC;
					font-weight: 500;
					color: #db1b22;
				}
			}
			.order_title {
				display: flex;
				padding: 30rpx;
				border-bottom: 1px solid #eeeeee;
				background-size: 28rpx 28rpx;
				background-color: #fff;
				.title_left {
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #111111;
					margin-right: 30rpx;
				}
				input{
					flex: 1;
					font-size: 28rpx;
				}
			}
			.voucher{
				padding: 30rpx;
				background-color: #fff;
				border-bottom: 1px solid #eeeeee;
				.voucher_title{
					font-size: 28rpx;
					font-family: PingFangSC-Regular, PingFang SC;
					font-weight: 400;
					color: #111111;
				}
				.voucher_content{
					display: flex;
					margin: auto;
					margin-top: 20px;
					flex-flow:wrap ;
				}
				.sctu{
					width:80px;
					height:80px;
					margin-right: 15px;
				}
				.jia{
					width:80px;
					height:80px;
					background-color:#C8C7CC;
					color:#808080;
					text-align: center;
					line-height: 80px;
					font-size: 30px;
					font-weight: 700;
				}
			}
			
			.button {
					width: 90%;
					margin: 0 auto;
					padding: 40rpx 0;
					button{
						border-radius: 20px;
						line-height: 80rpx;
					}
				}
		}
</style>
